/*
 * Created on Jan 5, 2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package littlecyberwar.model;

import java.util.Properties;
import java.io.*;

/**
 * @author Milton  Soong
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class FileCmdBackingStore implements CmdBackingStore {
	File f;
	ObjectOutputStream oo;
	
	public FileCmdBackingStore( File fIn ) {
		f = fIn;
		open(null);		
	}
	/* (non-Javadoc)
	 * @see littlecyberwar.model.CmdBackingStore#open(java.util.Properties)
	 */
	public void open(Properties prop) {
		// TODO Auto-generated method stub
		try {
			FileOutputStream fo = new FileOutputStream( f );
			oo = new ObjectOutputStream ( fo );
		} catch ( Exception ex ) {
			ex.printStackTrace();
		}
	}

	/* (non-Javadoc)
	 * @see littlecyberwar.model.CmdBackingStore#add(littlecyberwar.model.Command)
	 */
	public void add(Command cmd) {
		// TODO Auto-generated method stub
		try {		
			oo.writeObject( cmd );
		} catch ( IOException ex ) {
			ex.printStackTrace();
		}	
	}

	/* (non-Javadoc)
	 * @see littlecyberwar.model.CmdBackingStore#close()
	 */
	public void close() {
		// TODO Auto-generated method stub
		try {
			oo.flush();
			oo.close();
		} catch ( IOException ex ) {
			ex.printStackTrace();
		}
	}

}
